package bancosys.tec.utils.db.converter;

import java.io.File;
import java.io.FileNotFoundException;
import java.net.MalformedURLException;
import java.net.URL;

/**
 * @author Rafael Volpato
 * @created May 30, 2007
 */
public class OracleToPostgreSQLDbConverter extends StatementDbConverter {

    /**
     * C'tor
     * 
     * @param inputFile the input file
     * @param outputFile the output file
     * @param dbName the database name
     * @throws FileNotFoundException if the input file is not found
     * @throws MalformedURLException if the input file uri is incorrect
     */
    public OracleToPostgreSQLDbConverter(File inputFile, File outputFile, String dbName) throws FileNotFoundException,
            MalformedURLException {
        super(inputFile, outputFile, dbName);
    }

    /**
     * C'tor
     * 
     * @param inputFile the input url
     * @param outputFile the output file
     * @param dbName the database name
     */
    public OracleToPostgreSQLDbConverter(URL inputFile, File outputFile, String dbName) {
        super(inputFile, outputFile, dbName);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    protected String convertStatement(String st) {
        String s = st;

        // Ignore
        if (s.startsWith("COMMENT")) {
            s = s.replaceAll(";", ".");
        }

        s = s.replaceAll("BOOL DEFAULT 0", "BOOL DEFAULT FALSE");
        s = s.replaceAll("BOOL DEFAULT 1", "BOOL DEFAULT TRUE");

        return s;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    protected boolean gotDelimiter(String line) {
        return line.matches("^" + this.getOldStatementDelimiterChar() + "$");
    }

    /**
     * {@inheritDoc}
     */
    @Override
    protected char getOldStatementDelimiterChar() {
        return '/';
    }

    /**
     * {@inheritDoc}
     */
    @Override
    protected char getNewStatementDelimiterChar() {
        return ';';
    }
}